import time

from selenium.webdriver.common.by import By

from common.Untils import QESDriver

class HomePage:


    def __init__(self):
        self.url = "http://8.155.1.153:8081/home"  # 首页对应的url
        self.driver = QESDriver.driver  # 创建驱动
        self.driver.get(self.url)  # 访问首页
    # 点击、查找首页对应的元素
    def GetHomePage(self):
        # 查找首页元素并截图
        home = self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[1]/nav/ol/li[2]/span[1]/span').click()
        #assert home == "首页"
        navigation_bar = self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[1]/div/div').text
        assert navigation_bar == "快速开始 / 便捷导航"  # 断言失败会直接报错
        QESDriver.GetScreenShot()
        ###################################################################
        # 依次点击“我的考试”“我的问卷”“问卷记录”“考试记录”标签
        self.driver.find_element(By.XPATH,
                                 '//*[@id="rc-tabs-0-panel-exam"]/div/div/div/div[2]/div/div/div/div/div/table/thead/tr/th[1]').click()
        self.driver.find_element(By.XPATH,
                                 '//*[@id="rc-tabs-0-panel-exam"]/div/div/div/div[2]/div/div/div/div/div/table/thead/tr/th[2]').click()
        self.driver.find_element(By.XPATH,
                                 '//*[@id="rc-tabs-0-panel-exam"]/div/div/div/div[2]/div/div/div/div/div/table/thead/tr/th[3]').click()
        self.driver.find_element(By.XPATH,
                                 '//*[@id="rc-tabs-0-panel-exam"]/div/div/div/div[2]/div/div/div/div/div/table/thead/tr/th[4]').click()
        # 点击创建问卷并截图
    def hp_CreateQuestionnaire(self):
            # 点击“创建问卷”按钮
            self.driver.find_element(By.XPATH,
                                     '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/a[1]').click()
            time.sleep(5)  # 等待页面跳转
            QESDriver.GetScreenShot()  # 截图记录创建问卷页面
            self.driver.back()  # 返回首页
            time.sleep(2)  # 等待页面跳转

        # 点击创建考试并截图
    def hp_CreateExaminations(self):
            # 点击“创建考试”按钮
            self.driver.find_element(By.XPATH,
                                     '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/a[2]').click()
            time.sleep(5)  # 等待页面跳转
            QESDriver.GetScreenShot()  # 截图记录创建考试页面
            self.driver.back()  # 返回首页
            time.sleep(2)  # 等待页面跳转



